<?php
//$Id: sms.php 497 2012-07-31 10:03:57Z tomqin@gmail.com $

/**
 * SMS 工具类
 *
 * @copyright       Copyright (C) 2010-2012 ARESCMS Inc.
 * @author          TomQin <tomqin@gmail.com>
 * @license         http://www.arescms.cn/license/
 * @package Core
 */
class SMS{
    var $msg = array();

    function sendSMS(array $mobile, $content, $stime = 0){
        foreach($mobile as $idx => $mob){
            if(!Util::isMobile($mob)){
                unset($mobile[$idx]);
            }
        }
        $mobile  = join(',', $mobile);
        $content = str_replace(',', '，', $content);

        //return $this->send('mt', $mobile, urlencode($content));
        return $this->send('', $mobile, urlencode($content));
    }

    private function send($func, $mobile, $content, $stime = 0){
        return true;
        switch($func){
            case 'mt':
                $usr = 'lingrui';
                $pwd = '888888';
                $api = "http://124.172.250.160/WebService.asmx/mt?Sn={$usr}&Pwd={$pwd}&mobile={$mobile}&content={$content}";
                $ret = Util::HttpRequest($api);
                $ret = intval($ret ? strip_tags($ret) : 999);
                $this->log($ret, $api);
                return ($ret === 0) ? true : false;
            break;
            default:
                $usr = 'kusotuan';
                $pwd = md5('993216');
                $api = "http://notice.zuitu.com/sms?user={$usr}&pass={$pwd}&phones={$mobile}&content={$content}";
                $ret = Util::HttpRequest($api);
                $this->log($ret, $api);
                return ($ret == '+OK') ? true : false;
            break;
        }
    }

    private function log($ret, $api){
        $txt = date('Y-m-d H:i:s').'|'.$ret.'|'.$api."\n";
        file_put_contents(DATA_DIR.'sms.txt', $txt, FILE_APPEND);
    }
}
?>